package collection;

import java.util.Deque;
import java.util.LinkedList;

/**
 * java.util.Deque接口 双端队列
 * Deque接口继承自Queue,双端队列的特点是队列两端都可以做出/入队操作
 * 常用实现类:java.util.LinkedList
 */
public class DequeDemo {
    public static void main(String[] args) {
        Deque<String> deque=new LinkedList<>();
        deque.offer("one");
        deque.offer("two");
        deque.offer("three");
        System.out.println(deque);

        deque.offerFirst("four");//队首方向入队
        System.out.println(deque);
        deque.offerLast("five");//队尾方向入队
        System.out.println(deque);

        String str=deque.poll();
        System.out.println(str);
        System.out.println(deque);

        str=deque.pollFirst();//队首方向出队
        System.out.println(str);
        System.out.println(deque);

        str=deque.pollLast();//队尾方向出队
        System.out.println(str);
        System.out.println(deque);

        str=deque.peekFirst();
        System.out.println(str);
        System.out.println(deque);

        str=deque.peekLast();
        System.out.println(str);
        System.out.println(deque);




    }
}
